package com.library.controller;

import com.library.po.BookInfo;
import com.library.service.BookInfoService;
import com.library.service.TypeInfoService;
import com.github.pagehelper.PageInfo;
import com.library.po.TypeInfo;
import com.library.utils.DataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

import static com.library.utils.Constants.FAIL_MSG;

@Controller
public class TypeInfoController {

    @Autowired
    private TypeInfoService typeInfoService;
    @Autowired
    private BookInfoService bookInfoService;

    @GetMapping("/typeIndex")
    public String typeIndex(){
        return "type/typeIndex";
    }

    @RequestMapping("/typeAll")
    @ResponseBody
    public DataInfo typeAll(String name, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "15") Integer limit){
        PageInfo<TypeInfo> pageInfo = typeInfoService.queryTypeInfoAll(name,page,limit);
        return DataInfo.ok("成功",pageInfo.getTotal(),pageInfo.getList());
    }

    @GetMapping("/typeAdd")
    public String typeAdd(){
        return "type/typeAdd";
    }

    @GetMapping("/queryTypeInfoById")
    public String queryTypeInfoById(Integer id, Model model){
        TypeInfo info= typeInfoService.queryTypeInfoById(id);
        model.addAttribute("info",info);
        return "type/updateType";
    }
}